package com.atguigu.practice;

import java.util.List;

public class TheMaxHappy {
    public static class Employee{
        public int happy; //这名员工自己的happy值
        public List<Employee> nexts; //这名员工的下级
    }
    public static class Info{
        public int laiMaxHappy;
        public int buMaxHappy;
        public Info(int lai,int bu){
            laiMaxHappy=lai;
            buMaxHappy=bu;
        }
        public static Info process(Employee x){
            if(x.nexts.isEmpty()){
                return new Info(x.happy,0);
            }
            int lai=x.happy; //x来的情况下
            int bu=0; //x不来的情况
            for(Employee next:x.nexts){
                Info nextInfo=process(next);
                lai+=nextInfo.buMaxHappy;
                bu+=Math.max(nextInfo.laiMaxHappy,nextInfo.buMaxHappy);
            }
            return new Info(lai,bu);
        }
    }
}
